<xsl:template name="Show-cqwpPaging" match="Row[@Style='Show-cqwpPaging']" mode="itemstyle">
	<xsl:param name="CurPos" />
	<xsl:param name="LastRow" />
	
	<!-- for paging need a querystring like: your-SharePoint-url.aspx?p=1 -->
	<xsl:variable name="parametriQueryString">
		<xsl:value-of select="substring-after($PageUrl,'?')" />
    </xsl:variable>
	<!-- you can rename your querystring ?page=1 too -->
	<xsl:variable name="numeroPagina">
		<xsl:value-of select="substring-after($parametriQueryString,'p=')" />
	</xsl:variable>
	
	<!-- can delete this display none after binding your fields in cqwp design properties-->
	<div style="display:none">
		<xsl:value-of select="@Title" /> - curpos: <xsl:value-of select="$CurPos" /> - lastrow: <xsl:value-of select="$LastRow" />
	</div>
	
   <xsl:variable name="titolo" select="@Title" />
    	
		<!-- here you can set page size -->
		<xsl:variable name="PageSize">
			<xsl:value-of select="20" />
		</xsl:variable>
		
	
        <!-- need add template to do this in foreach -->
        <!-- like ($CurPos &lt; $PageSize + 1 ) or (($CurPos &lt; ($PageSize * 2) + 1 )...) -->
		<!-- now run only for 5 pages (it's static!) -->
		
		<xsl:if test="($CurPos &lt; 21 and $numeroPagina = 1) or 
					($CurPos &lt; 41 and $CurPos &gt; 21 and $numeroPagina = 2) or 
					($CurPos &lt; 61 and $CurPos &gt; 41 and $numeroPagina = 3) or 
					($CurPos &lt; 81 and $CurPos &gt; 61 and $numeroPagina = 4) or 
					($CurPos &lt; 101 and $CurPos &gt; 81 and $numeroPagina = 5)">
			
			<!-- here can set fields to display -->
			<div class="yourCssClasses"> 
					<span class="title">
						<xsl:value-of select="@Title" /> 
					</span>
					<span class="clear">&#160;</span>
		    </div>
	
			
			<xsl:variable name="numeroPagineDiv">
				<xsl:value-of select="ceiling($LastRow div $PageSize)" />
			</xsl:variable>
			
			<!-- Last page number records -->
			<xsl:variable name="numeroRecordUltimaPagina">
				<xsl:value-of select="$LastRow mod $PageSize" />	
			</xsl:variable>
				
			<xsl:if test="$PageSize mod 20 = 0">
				<xsl:variable name="numeroElementi20">
					<xsl:value-of select="$CurPos mod 20" />
				</xsl:variable>
			</xsl:if>
			
			<xsl:if test="($CurPos mod 20 = 0 and $PageSize &gt; 0) or ($CurPos = $LastRow and $numeroRecordUltimaPagina &gt; 0)">
			
				<xsl:variable name="NumPages">
					<xsl:value-of select="ceiling($LastRow div $PageSize)" />
				</xsl:variable>
			
			<!-- call paging templates  -->
				<xsl:if test="$NumPages &gt; 1">
					<xsl:call-template name="Show-PagingControls">
						  <xsl:with-param name="Page" select="1" />
						  <xsl:with-param name="NumPages" select="$NumPages" />
						  <xsl:with-param name="Title" select="@Title" />
						  <xsl:with-param name="LastRow" select="$LastRow" />
					 </xsl:call-template>
				</xsl:if>
					
			</xsl:if>
		</xsl:if>
	</xsl:template>
	<xsl:template name="Show-PagingControls">
	<xsl:param name="Page" />
	<xsl:param name="NumPages" />
	<xsl:param name="Title" />
	<xsl:param name="LastRow" />

	<xsl:variable name="parametriQueryString">
    	<xsl:value-of select="substring-after($PageUrl,'?')" />
    </xsl:variable>
	<xsl:variable name="PageNumber">
		<xsl:value-of select="substring-after($parametriQueryString,'p=')" />
    </xsl:variable>

    <xsl:variable name="paramPagination">
		<xsl:value-of select="substring-before($PageUrl,'?')" />
	 </xsl:variable>	
	
	<!-- if first page -->
   	<xsl:if test="$Page = 1">
	   <xsl:text disable-output-escaping="yes"><![CDATA[<div class="numericPaging">]]></xsl:text>
	   <div class="itemsNumber">
			<xsl:value-of select="$LastRow" /> Numero di elementi: 
	   </div>
	
		<!-- pagine precedenti PREVIOUS PAGE  -->
		<xsl:if test="$PageNumber &gt; 1">
			<xsl:variable name="PreviousPageNo" select="$PageNumber - 1"/>
			<a href="{$paramPagination}?p={$PreviousPageNo}">	
				<img src="/PublishingImages/grafica/prev.png" title="Prev"  />
			</a>
		</xsl:if>
    </xsl:if>
    
	<xsl:choose>
	<!-- se sono nella PAGINA CORRENTE non aggiungo link - current page no link in pagination -->
	  <xsl:when test="$Page = $PageNumber">
		  <strong>
			<xsl:value-of select="$Page"/>
		  </strong>
	  </xsl:when>
	  
	    <!-- altrimenti PAGINAZIONE -->
	    <xsl:otherwise>
			<a href="{$paramPagination}?p={$Page}">
			  <xsl:value-of select="$Page"/>
		   </a>			
		</xsl:otherwise>
    </xsl:choose>

    <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
	
	<!-- se ho altre pagine richiamo lo stesso template passandogli param pages + 1 -->
	<!-- Cosi costruiscono 1,2, 3, ecc, pagine -->
    <xsl:if test="$Page &lt; $NumPages">
		  <xsl:call-template name="Show-PagingControls">
				<xsl:with-param name="Page" select="$Page + 1"/>
				<xsl:with-param name="NumPages" select="$NumPages" />
				<xsl:with-param name="Title" select="$Title" />
				<xsl:with-param name="LastRow" select="$LastRow" />
		  </xsl:call-template>
    </xsl:if>
    
	<!-- se ho altre PAGINE SUCCESSIVE - for next pages -->
    <xsl:if test="$Page = $NumPages">
      <xsl:if test="$PageNumber &lt; $NumPages">     
		  <xsl:variable name="NextPageNo" select="$PageNumber + 1"/>
				<a href="{$paramPagination}?p={$NextPageNo}">
					<img src="/PublishingImages/grafica/next.png" title="Next" />
				</a>
		<xsl:text disable-output-escaping="yes"><![CDATA[</div>]]></xsl:text>
		</xsl:if>
	</xsl:if>
</xsl:template>